"""
    初始化alipay对象，并定义一些常用方法
"""
from alipay import AliPay
from django.views import View

from midproject import settings


class MyAlipay(View):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        self.alipay = AliPay(
            # 应用ID，控制台获取
            appid=settings.ALIPAY_APPID,
            # 异步通知地址，必须为公网IP
            app_notify_url=settings.ALIPAY_NOTIFY_URL,
            # 应用私钥，用户签名
            app_private_key_string=str(open(settings.ALIPAY_KEY_DIR + "app_private_key.pem").read()),
            # 支付宝公钥，用于验签
            alipay_public_key_string=str(open(settings.ALIPAY_KEY_DIR + "alipay_public_key.pem").read()),
            # 签名使用算法
            sign_type="RSA2",
            # 请求转发至沙箱环境
            debug=True,
        )
